<%@page import="java.sql.*"%>
<%@page import="javabean.JDBCBean"%>
<%@ page import="servlet.admin.isbn_inf" %>

<%@page import="com.alibaba.fastjson.JSON" %>
<%@page import="com.alibaba.fastjson.JSONObject" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>bookadd</title>
    <!-- layui -->
    <link rel="stylesheet" href="../public/layui/css/layui.css">
    <link rel="stylesheet" href="css/qrm-pinming.css">
    <script src="../public/layui/layui.js"></script>

    <style>
        .layui-form{
            margin: 10px 20px;

        }
    </style>
    </style>
</head>
<body>
<jsp:useBean id="borrow" scope="session" class="javabean.JDBCBean"></jsp:useBean>

<%
    ResultSet librarySet = null;
    ResultSet bookSortSet = null;
    // 获取图书馆列表
    JDBCBean db2 = new JDBCBean();
    String librarySql = "select * from library";
    librarySet = db2.executeQuery( librarySql );
    // 获取书籍分类
    JDBCBean db3 = new JDBCBean();
    String bookSortSql = "select * from book_sort";
    bookSortSet = db3.executeQuery( bookSortSql );
    String apikey="12469.fcd2ac4e9b8099d51e8db251737d84b8.ed524086f8e7ec7c9d0aaa5c9c3dd350";
    int i=99;
    int j=1;
//    String isbn = "9787020024759";

%>
<%--  <button id="searches"  type="submit" style="position: relative; left: 320px; top: 40px; z-index: 99">search</button>--%>
<%--<input type="submit"  value="search" onclick="javascript:void(0);"style="position: relative; left: 320px; top: 40px; z-index: 99">--%>
<form class="layui-form   layui-form-pane" action="" style="width: 400px">
    <input type="id" name="id" value="3" class="layui-hide">
<%--    <div class="layui-form-item">--%>
<%--        <label class="layui-form-label">ISBN</label>--%>
<%--        <div class="layui-input-block">--%>
<%--            <input type="text" id="ISBN" name="ISBN" required="" lay-verify="required" placeholder="Input ISBN" autocomplete="off" class="layui-input" style="width: 180px">--%>

<%--        </div>--%>

<%--    </div>--%>
    <div class="layui-form-item">
        <label class="layui-form-label">Book name</label>
        <div class="layui-input-block">
            <input type="text" id="name" name="name" required="" lay-verify="required" placeholder="Input book's name" autocomplete="off" class="layui-input" readonly style="width: 300px">
        </div>
    </div>
    <!-- 作者 -->
    <div class="layui-form-item">
        <label class="layui-form-label">author</label>
        <div class="layui-input-block">
            <input type="text" id="author" name="author" required  lay-verify="required" placeholder="Input book's author" autocomplete="off" class="layui-input" readonly style="width: 300px">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">Library</label>
        <div class="layui-input-block">
            <select name="library_id" lay-verify="required">
                <option value=""></option>
                <% while( librarySet.next() ){ %>
                <option value=<%=librarySet.getString("id") %>  ><%=librarySet.getString("name") %></option>
                <%} %>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">Location</label>
        <div class="box" >
            <div class="qrm-pinming">
                <div class="qrm-input-border">
                    <!--<span class="title">品名</span>-->
                    <input type="text" name="location" required="" lay-verify="required" placeholder="请选择" class="qrm-input" style="position: absolute;
    left: 115px;" readonly >
                </div>
                <!--<div class="qrm-pinming-panel" style="display:none">-->
                <div class="qrm-border1" style="display:none">
                    <ul class="qrm-lev-1 qrm-lev">
                        <!--统料-->
                        <li class="active">
                            <span>我是一级01</span><i class="qrm-arrow-right"></i>
                            <ul class="li-zi-1" style="display: none">
                                <li>
                                    <span>我是二级01</span><i class="qrm-arrow-right"></i>
                                    <ul class="li-zi-2" style="display: none">
                                        <li>
                                            <span>我是三级11</span>
                                        </li>
                                        <li>
                                            <span>我是三级12</span>
                                        </li>
                                        <li>
                                            <span>我是三级13</span>
                                        </li>
                                    </ul>
                                </li>
                                <li>
                                    <span>我是二级02</span><i class="qrm-arrow-right"></i>
                                    <ul class="li-zi-2" style="display: none">
                                        <li>
                                            <span>我是三级21</span>
                                        </li>
                                        <li>
                                            <span>我是三级22</span>
                                        </li>
                                        <li>
                                            <span>我是三级23</span>
                                        </li>
                                    </ul>
                                </li>
                                <li>
                                    <span>我是二级03</span><i class="qrm-arrow-right"></i>
                                    <ul class="li-zi-2" style="display: none">
                                        <li>
                                            <span>我是二级03</span><i class="qrm-arrow-right"></i>
                                            <ul class="li-zi-3" style="display: none">
                                                <li>
                                                    <span>我是三级31</span>
                                                </li>
                                                <li>
                                                    <span>我是三级32</span>
                                                </li>
                                                <li>
                                                    <span>我是三级33</span>
                                                </li>
                                            </ul>
                                        </li>
                                        <li>
                                            <span>我是三级32</span>
                                        </li>
                                        <li>
                                            <span>我是三级33</span>
                                        </li>
                                    </ul>
                                </li>
                                <li>
                                    <span>我是二级04</span>
                                </li>
                            </ul>
                        </li>
                    </ul>
                    <p class="clearfix"></p>
                </div>
                <div class="qrm-border2" style="display:none">
                    <ul class="qrm-lev-2 qrm-lev">

                    </ul>
                    <p class="clearfix"></p>
                </div>
                <div class="qrm-border3" style="display:none">
                    <ul class="qrm-lev-3 qrm-lev">

                    </ul>
                    <p class="clearfix"></p>
                </div>
                <div class="qrm-border4" style="display:none">
                    <ul class="qrm-lev-4 qrm-lev">

                    </ul>
                    <p class="clearfix"></p>
                </div>
                <p class="clearfix"></p>
                <!--</div>-->
                <p class="clearfix"></p>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">classification</label>
        <div class="layui-input-block">
            <select name="sort_id" lay-verify="required">
                <option value=""></option>
                <% while(bookSortSet.next()){ %>
                <option value=<%=bookSortSet.getInt("id") %> ><%=bookSortSet.getString("name") %></option>
                <%} %>
            </select>
        </div>
    </div>
<%--    <div class="layui-form-item">--%>
<%--        <label class="layui-form-label">Count</label>--%>
<%--        <div class="layui-input-block">--%>
<%--            <input type="text" name="count" required="" lay-verify="required" placeholder="Input location id" autocomplete="off" class="layui-input">--%>
<%--        </div>--%>
<%--    </div>--%>
<div class="layui-form-item">
    <label class="layui-form-label">Count</label>
    <div class="layui-input-block">
        <select name="count" lay-verify="required">
            <option value=""></option>
            <% for(j=1;j<=i;j++){ %>
            <option value=<%=j %>  ><%=j %></option>
            <%} %>
        </select>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">State</label>
        <div class="layui-input-block">
            <input type="radio" name="status" value="1" title="可借" checked="checked"><div class="layui-unselect layui-form-radio layui-form-radioed"><i class="layui-anim layui-icon"></i><div>可借</div></div>
            <input type="radio" name="status" value="0" title="不可借"><div class="layui-unselect layui-form-radio"><i class="layui-anim layui-icon"></i><div>不可借</div></div>
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">Book Description</label>
        <div class="layui-input-block">
            <textarea class="layui-textarea" id="description" name="description" lay-verify="content" id="LAY_demo_editor"></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="bookForm">Submit</button>
            <button type="reset" class="layui-btn layui-btn-primary">Reset</button>
        </div>
    </div>
</form>
<script src="js/jquery.min.js"></script>
<script src="js/qrm-pinming.js"></script>
<%--  <script>--%>

<%--    document.getElementById("searches").onclick=function () {--%>
<%--      var str =document.getElementById("ISBN");--%>
<%--      // var isbn = document.createAttribute("ISBN");--%>
<%--      // isbn.value=st--%>
<%--      <%--%>
<%--        String isbn = request.getParameter("ISBN");--%>

<%--//        isbn_inf infa = new isbn_inf(isbn,apikey);--%>
<%--      %>--%>
<%--      console.log(<%=isbn%>);--%>
<%--//--%>
<%--        document.getElementById("name").value=<%=isbn%>;--%>
<%--        document.getElementById("author").value="456";--%>
<%--        document.getElementById("description").value="789";--%>

<%--    }--%>
<%--  </script>--%>
<script>
    $(function(){
            console.log(123)

<%
//            Object is = session.getAttribute("bookname");
                        String isbn=request.getParameter("ISBN");
//                        Object name = session.getAttribute("bookname");

                           if(isbn==null){
                           isbn="123456789";
                            }



                            isbn_inf infa = new isbn_inf(isbn,apikey);
                           if(infa!=null){
                                String name = infa.name;

                           String author =infa.author;
                           String des = infa.description;


                          %>
                            document.getElementById("name").value="<%=name%>";
                            document.getElementById("author").value="<%=author%>";
                            document.getElementById("description").value="<%=des%>";
        <%}else{%>
        layer.msg(layer.msg("re-enter isbn"))
        location.href="bookaddisbn.jsp"

        <%}%>
            // var str =document.getElementById("ISBN");
            // var isbn = document.createAttribute("ISBN");
            // isbn.value=st
    })
</script>
<script>


    layui.use(['form', 'layedit', 'jquery'], function(){
        //layer.closeAll();
        $ = layui.jquery;
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit;
        /**
         * 因为富文本存在xss注入，以下代码不用了，如果需要可以开启
         */
        /*
        var editIndex = layedit.build('LAY_demo_editor');
        // 自定义验证规则
        form.verify({
            // 解决富文本异步传输问题
            content: function(value){
                return layedit.sync(editIndex);
            }
        })
        */
        //监听提交
        form.on('submit(bookForm)', function(data){
            $.ajax({
                url: './bookAdd',
                method: 'post',
                data: data.field, //JSON.stringify(data.field),
                dataType: 'JSON',
                success: function(data){
                    if(data.code == "0"){
                        parent.layer.msg("添加成功",{
                            icon: 6,
                            time: 500
                        });
                        setTimeout(function(){
                            //parent.location.reload();
                            var index = parent.layer.getFrameIndex(window.name); //操作父页面
                            parent.layer.close(index);
                        }, 500);
                    }else{
                        leyer.msg("添加失败");
                    }
                }
            })


            return false;
        });
    });

</script>

</body>
</html>